import socketio
from flask import Flask
from flask_restful import Api
from sqlalchemy.dialects import mysql
from views import MessageResource, RealTimeChatResource, LoginResource, RegisterResource, \
    UserInfoResource, UpdateUserInfoResource, UpdatePasswordResource, \
    ManageUserList, AdminFeedbackResource, UserFeedbackResource, UpdateUserStatusResource, DeleteUserResource, \
    ChangePasswordResource


def register_routes(app: Flask):
    api = Api(app)  # 创建 Api 实例
    api.add_resource(MessageResource, '/user/messages/')  # 绑定路由到视图函数
    api.add_resource(RealTimeChatResource, '/user/chat', resource_class_args=[mysql, socketio])
    api.add_resource(LoginResource, '/user/login')
    api.add_resource(RegisterResource, '/user/register')
    api.add_resource(UserInfoResource, '/user/userinfo')
    api.add_resource(UpdateUserInfoResource, '/user/update_userinfo')
    api.add_resource(UpdatePasswordResource, '/user/update_password')
    api.add_resource(UserFeedbackResource, '/user/feedback')
    # 管理员
    api.add_resource(AdminFeedbackResource, '/admin/feedback')
    api.add_resource(ManageUserList, '/admin/users')
    api.add_resource(UpdateUserStatusResource, '/admin/update_user_status/<int:user_id>')
    api.add_resource(DeleteUserResource, '/admin/delete_user/<int:user_id>')
    api.add_resource(ChangePasswordResource, '/admin/update_password/<int:user_id>')
